package com.demo.response;

import lombok.Data;

/**
 * @Description: 统一返回类
 * @Author: 张金志
 * @Time: 2017/12/25 15:15
 */
@Data
public class BaseResponse<T> {
    private String respCode;
    private String respMsg;
    private T data;

    public BaseResponse success(T data) {
        BaseResponse baseResponse = new BaseResponse();
        baseResponse.setRespCode("000000");
        baseResponse.setRespMsg("操作成功");
        baseResponse.setData(data);
        return baseResponse;
    }

    public BaseResponse error() {
        BaseResponse baseResponse = new BaseResponse();
        baseResponse.setRespCode("500");
        baseResponse.setRespMsg("操作失败");
        return baseResponse;
    }

//    public BaseResponse error(RespCodeEnum respCodeEnum,T data){
//        BaseResponse baseResponse = new BaseResponse();
//        baseResponse.setRespCode(respCodeEnum.getCode());
//        baseResponse.setRespMsg(respCodeEnum.getName());
//        baseResponse.setData(data);
//        return baseResponse;
//    }

    public static <T> BaseResponse Tsuccess(T data) {
        BaseResponse baseResponse = new BaseResponse();
        baseResponse.setRespCode("000000");
        baseResponse.setRespMsg("操作成功");
        baseResponse.setData(data);
        return baseResponse;
    }

    public static <T> BaseResponse Terror(String respMsg) {
        BaseResponse baseResponse = new BaseResponse();
        baseResponse.setRespCode("500");
        baseResponse.setRespMsg(respMsg);
        return baseResponse;
    }

    public static <T> BaseResponse codeMsg(String code, String respMsg) {
        BaseResponse baseResponse = new BaseResponse();
        baseResponse.setRespCode(code);
        baseResponse.setRespMsg(respMsg);
        return baseResponse;
    }
}
